package app.champaign;

import java.util.ArrayList;
import java.util.List;

class getO {

    public static void main(String[] args) {
        Dot d1 = new Dot(0, 0);
        Dot d2 = new Dot(2,9);
        Dot d3 = new Dot(8,3);
       
        Dot[] dots = {d1, d2, d3};
        
        String result = getCircle(dots);
        System.out.println(result);
    }
    public static String getCircle(Dot[] dots){
        if(dots == null || dots.length < 3){
            return "请输入有效个数的点";
        }
        double x1 = dots[0].x, x2 = dots[1].x, x3 = dots[2].x;
        double y1 = dots[0].y, y2 = dots[1].y, y3 = dots[2].y;
        double a = x1 - x2;
        double b = y1 - y2;
        double c = x1 - x3;
        double d = y1 - y3;
        double e = ((x1 * x1 - x2 * x2) + (y1 * y1 - y2 * y2)) / 2.0;
        double f = ((x1 * x1 - x3 * x3) + (y1 * y1 - y3 * y3)) / 2.0;
        double det = b * c - a * d;
        if(a/b == c/d) {
            return "三点共线，输入错误";
        }   
        double x0 = -(d * e - b * f) / det;
        double y0 = -(a * f - c * e) / det;

        double R = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);

        double r =  Math.sqrt(R);



        return  "x0:"+x0+", y0:"+y0+", r:"+r;
    }

    public static class Dot{
        double x;
        double y;
        public Dot(double x, double y){
            this.x = x;
            this.y = y;
        }
        public Dot(){
           super();
        }
    }

}